package com.example.task1.ui.AllService.logistics;

import android.os.Bundle;
import android.text.Html;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.LogisticsDetailsBean;
import com.example.task1.http.Api;
import com.example.task1.util.ApiResp;
import com.example.task1.util.CallBack;

import retrofit2.Call;

public class LogisticsDetailsActivity extends AppCompatActivity {

    private int id;
    private TextView tvTitle;
    private ImageView image;
    private TextView tvContext;
    private TextView tvMethod;
    private TextView tvPhone;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_logistics_details);
        ActionBar supportActionBar = getSupportActionBar();
        supportActionBar.setTitle("物流公司详情");
        supportActionBar.setDisplayHomeAsUpEnabled(true);
        id = getIntent().getIntExtra("id", 0);
        initData();
        initView();
    }

    @Override
    public boolean onOptionsItemSelected(@NonNull MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            finish();
        }
        return super.onOptionsItemSelected(item);
    }

    private void initData() {
        Call<ApiResp> apiRespCall = Api.api().get(MyApplication.TOKEN, "/prod-api/api/logistics-inquiry/logistics_company/" + id);
        Api.send(apiRespCall, LogisticsDetailsBean.class, new CallBack<LogisticsDetailsBean>() {
            @Override
            public void success(LogisticsDetailsBean data) {
                LogisticsDetailsBean.DataDTO rows = data.getData();
                tvTitle.setText(rows.getName());
                tvContext.setText(Html.fromHtml(rows.getIntroduce()));
                tvMethod.setText("运输方式：" + rows.getShippingMethod());
                tvPhone.setText("联系方式：" + rows.getPhone());
                MyApplication.glide(image, rows.getImgUrl());
            }

            @Override
            public void error(String msg) {

            }
        });
    }

    private void initView() {
        tvTitle = (TextView) findViewById(R.id.tv_title);
        image = (ImageView) findViewById(R.id.image);
        tvContext = (TextView) findViewById(R.id.tv_context);
        tvMethod = (TextView) findViewById(R.id.tv_method);
        tvPhone = (TextView) findViewById(R.id.tv_phone);
    }
}